home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 16 / PC Actual CD 16.iso / cdactual / Os2 / 0509 / EditToolbar.java < prev    next >
Encoding:
Java Source  |  1997-08-19  |  3.1 KB  |  109 lines

  1. package macrolanguage;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import macrolanguage.*;
  5.  
  6. /**
  7.  * The class EditToolbar supplies a toolbar for adding and manipulating
  8.  * objects on the FreeFormEdit.
  9.  * EditToolbar is simply a user interface class which delegates all of
  10.  * the functionality to the free form editing.
  11. **/
  12. public class EditToolbar extends Window implements ActionListener
  13. {
  14.   /**
  15.    * The constructor sets the UI to the correct appearance.
  16.   **/
  17.   public EditToolbar(FreeFormEdit form)
  18.   {
  19.     super(form);
  20.  
  21.     // The FreeFormEdit instance owning this toolbar.
  22.     this.form = form;
  23.  
  24.     // The default layout currently. This is subject to
  25.     // profound change.
  26.     setLayout(new FlowLayout());
  27.  
  28.     // Adding the components to the toolbar.
  29.     add(classNameEntry);
  30.     add(addClassButton);
  31.     add(deleteSelectedButton);
  32.     add(exitButton);
  33.  
  34.     // Listening to the component events.
  35.     addClassButton.addActionListener(this);
  36.     deleteSelectedButton.addActionListener(this);
  37.     exitButton.addActionListener(this);
  38.  
  39.     // Set the size of the window to fit the Components in it.
  40.     pack();
  41.  
  42.     // Set the FreeFormEdit to be right under this window.
  43.     form.setLocation(getLocation().x , getLocation().y + getSize().height);
  44.  
  45.     // Show the window.
  46.     show();
  47.   }
  48.  
  49.   public void actionPerformed(java.awt.event.ActionEvent ev)
  50.   {
  51.     // If the aa button is pressed.
  52.     if(ev.getSource() == addClassButton)
  53.     {
  54.       // Find the class coresponding to the string in
  55.       // the text entry and create an instance of it.
  56.       Object temp = loader.loadObject(classNameEntry.getText());
  57.  
  58.       // If the instance is not invalid then enter add
  59.       // a new component mode with this Component.
  60.       if(temp == null)
  61.       {
  62.         System.out.println("Class loading error.");
  63.         return;
  64.       }
  65.       if (temp instanceof Component)
  66.       {
  67.         form.placeComponentOnNextClick((Component)temp);
  68.         System.out.println("Successfully loaded " + temp.toString());
  69.       }
  70.       else
  71.       {
  72.         System.out.println("You can only place subclasses of the class Component on the freeform edit.");
  73.       }
  74.     }
  75.  
  76.     // If the delete button is pressed then delete the
  77.     // selected Component.
  78.     if(ev.getSource() == deleteSelectedButton)
  79.     {
  80.       form.removeSelection();
  81.     }
  82.  
  83.     // If the exit button is pressed then ...
  84.     if(ev.getSource() == exitButton)
  85.     {
  86.       System.exit(0);
  87.     }
  88.   }
  89.  
  90.   // Used to load new instances of components automaticaly.
  91.   private MacroExtension loader = new MacroExtension();
  92.  
  93.   // The owner FreeFormEdit.
  94.   private FreeFormEdit form;
  95.  
  96.   // The entry field in which you select the name of the class
  97.   // to add to the free form edit.
  98.   private TextField classNameEntry = new TextField("java.awt.Button");
  99.  
  100.   // Add the class whos name appears in the classNameEntry field.
  101.   private Button addClassButton = new Button("Add class");
  102.  
  103.   // Delete the selected Component.
  104.   private Button deleteSelectedButton = new Button("Delete selected");
  105.  
  106.   // Exit the application.
  107.   private Button exitButton = new Button("Exit");
  108. }
  109.